﻿<script src="~/Scripts/jquery-easyui-extensions/portal/jquery.portal.original.js"></script>
<style>
    .changeLog {
    }

        .changeLog li {
            padding: 5px;
        }

    .donateList {
        list-style:none;
    }

        .donateList li {
        }

    .donate-name {
        font-weight: bold;
        line-height: 14px;
        background-color: rgb(70, 136, 71);
        color: #fff;
        padding-top: 2px;
        padding-bottom: 2px;
        padding-left: 4px;
        padding-right: 4px;
        border-radius: 3px;
    }

    .donate-date {
        padding: 5px;
    }

    .donate-total {
        font-weight: bold;
        color: Red;
    }
</style>
<div id="deskLayout" class="easyui-layout" data-options="fit:true">
    <div data-options="region:'north',border:false" style="height: 60px; font-size: 16px; font-weight: bold; padding: 20px 10px; background: #eee; overflow: hidden; border-bottom-width: 1px; ">
        Easyui扩展整理库。
        <a id="btnSearchApi" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-search'" >站内搜索扩展</a>
        <span style="font-size:25px;font-weight:bolder;color:red;"><==看这里</span>
    </div>
    <div id="portalContainer" data-options="region:'center',border:false,title:'当前 Easyui 版本：1.4.3'">
        <div id="portal" class="easyui-portal" data-options="fit:true,border:false">
            <div style="width:60%;">
                <div title="更新日志" style="height:350px;padding:5px;">
                    <ul id="ulChangeLog" class="changeLog"></ul>
                </div>
            </div>
            <div style="width:40%;">
                <div title="开源" style="height: 350px; padding: 5px;">
                    <a id="btnAlipay" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-alipay'">若有所收获，可以点击支付宝捐赠我。</a>
                    <a id="btnWeixinpay" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-weixin'">若有所收获，可以点击微信捐赠我。</a>
                    <div id="divAlipay" style="width:175px;height:15px;"></div>
                    <div id="divWeixinpay" style="width:175px;height:15px;"></div>
                    <ul id="ulDonateLog" class="donateList">
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>

<script>

    window.deskIndex = {};
    window.deskIndex.resizePortal = function (resizeFull) {
        var port = $("#portal"), portalHeight = port.height(), internalPadding = 10, containerHeight = $("#portalContainer").height(),
                panels = port.portal("getPanels");
        //console.log("容器高度：" + containerHeight); console.log("portal高度：" + portalHeight);
        //console.log("panel原高度：" + panels[0].panel("options").height);
        $.array.forEach(panels, function (item) {
            item.panel("options").height = containerHeight - (2 * internalPadding) - 13;
        });
        if (portalHeight < containerHeight) {
            var newSize = { height: containerHeight };
            port.portal("resize", newSize);
        } else {
            port.portal("resize");
        }
        //console.log("panel新高度：" + panels[0].panel("options").height);
        if (resizeFull) {
            
        }
    };

    $(function () {
        var changeLogsUl = $("#ulChangeLog");
        $.getJSON("/Common/changeLogs-data.json", function (json) {
            $.array.forEach(json, function (item) {
                $("<li />").html("[ " + item.Date + " ] <b>" + item.Log + "</b>").appendTo(changeLogsUl);
            });

        });

        var donateLogsUl = $("#ulDonateLog");
        $.getJSON("/Common/donate-data.json", function (json) {
            $.array.forEach(json, function (item) {
                $("<li />").html("<span class=\"donate-name\">" + item.RealName + " " + item.Email + "</span><span class=\"donate-date\">" + item.Date + "</span><span>(</span><span class=\"donate-total\">" + item.Total + "</span><span>元)</span>").appendTo(donateLogsUl);
                $("<br />").appendTo(donateLogsUl);
            });
        });

        var showPay = function () {
            var t = $("#divAlipay"),
                opts = {
                    position: "right",
                    content: "<img src=\"/Content/images/alipay.png\" title=\"感谢你支持我\" />"
                };
            $("#btnAlipay").click(function () {
                t.tooltip($.extend({ trackMouse: false }, opts, {
                    onHide: function () {
                        if ($.isFunction(opts.onHide)) { opts.onHide.apply(this, arguments); }
                        t.tooltip("destroy");
                    }
                })).tooltip("show");
            });

            var t2 = $("#divWeixinpay"),
                opts2 = {
                    position: "right",
                    content: "<img src=\"/Content/images/weixinpay.png\" title=\"感谢你支持我\" />"
                };
            $("#btnWeixinpay").click(function () {
                t2.tooltip($.extend({ trackMouse: false }, opts2, {
                    onHide: function () {
                        if ($.isFunction(opts2.onHide)) { opts2.onHide.apply(this, arguments); }
                        t2.tooltip("destroy");
                    }
                })).tooltip("show");
            });
        };

        showPay();

        setTimeout(window.deskIndex.resizePortal, 500);

        $("#btnSearchApi").click(function () {
            $.messager.prompt("搜索 ext-lib 内的扩展", "请输入搜索关键字：", function (key) {
                if (typeof (key) != "undefined") {
                    var dia = $("<div />").appendTo("body");

                    dia.dialog({
                        title: "搜索结果",
                        width: 650,
                        height: 450,
                        buttons: [{ text: "关闭", iconCls: "icon-cancel", handler: function () { dia.dialog("destroy"); } }],
                        onClose: function () {
                            $(this).dialog("destroy");
                        }
                    });

                    var body = dia.dialog("body");
                    var container = $("<div />").appendTo(body).css({
                        "padding": "25px"
                    });
                    container.html("搜索进行中...");

                    window.extlib.common.searchApi(key, function (result) {
                        console.log("搜索结果：");
                        console.log(result);

                        if (!result.length) {
                            container.html("未搜索到[" + key + "]相关的扩展内容，请尝试用其他关键字进行搜索。");
                            return;
                        }
                        var loadData = function (table, data) {
                            $.array.forEach(data, function (item) {
                                console.log("追加" + item.match);
                                var module = item.module, extension = item.extension, match = item.match;
                                var tr = $("<tr />");
                                $("<td />").html(module).appendTo(tr);
                                $("<td />").html(extension).appendTo(tr);
                                $("<td />").html(match).appendTo(tr);
                                var btnView = $("<a />");
                                $("<td />").append(btnView).appendTo(tr);
                                tr.appendTo(table);

                                btnView.linkbutton({
                                    iconCls: "icon-ok",
                                    plain: true,
                                    text: "查看",
                                    onClick: function () {
                                        var tr = $(this).parents("tr:first");
                                        var t1 = tr.find("td:eq(0)").text(),
                                            t2 = tr.find("td:eq(1)").text(),
                                            t3 = tr.find("td:eq(2)").text();
                                        var url = window.location.protocol + "//" + window.location.host + "/Public/ExampleIndex";
                                        window.extlib.common.windowOpen(url, { module: t1, extension: t2 }, $.util.windowSize());
                                    }
                                });
                            });
                        };

                        if (container.html() == "搜索进行中...") {
                            container.html("搜索结果如下：");

                            var table = $("<table />").addClass("tableAPI");
                            var tr = $("<tr />").addClass("title");
                            $("<td />").html("模块").css("width", "33%").appendTo(tr);
                            $("<td />").html("扩展标识").css("width", "33%").appendTo(tr);
                            $("<td />").html("api名称").appendTo(tr);
                            $("<td />").html("").appendTo(tr);
                            tr.appendTo(table);

                            container.append(table);

                            loadData(table, result);
                        } else {
                            var table = container.find("table");
                            loadData(table, result);
                        }
                    });
                }
            });
        });
    });
</script>